home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_069 / sb / sbio.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  6KB  |  212 lines

  1. /* include not needed for Aztec C using provided makefile */
  2. #include    "sb:sb.h"
  3.  
  4. #define        CHOICEWIDTH 280
  5. #define        CHOICEHEIGHT 8
  6. #define        SPACING 9
  7. #define        TOPGADG 30
  8. #define        PUTTEXT(text, x, y) { Move(rp, (long)x, (long)y); \
  9.                                   Text(rp, text, (long)strlen(text)); }
  10. struct    IntuitionBase     *IntuitionBase = NULL;
  11. struct    GfxBase        *GfxBase = NULL;
  12. struct    Window         *OpenWindow(), *MainWindow = NULL;
  13. struct    RastPort     *rp;
  14. extern    int         level;
  15. APTR    OpenLibrary();
  16. struct    IntuiText     ChoiceText[MAXGADG + 1];
  17. struct    Gadget         ChoiceGadg[MAXGADG + 1];
  18. extern    void         CloseOut(), Redisplay();
  19.  
  20. struct IntuiText BackIText = {
  21.         3, 2, JAM2,
  22.         5, 2,
  23.         NULL, NULL, NULL
  24.     };
  25. struct IntuiText MoreIText = {
  26.         2, 3, JAM2,
  27.         5, 2,
  28.         NULL,
  29.         (UBYTE *)"(MORE)",
  30.         NULL
  31.     };
  32. struct Gadget BackGadg = {
  33.         NULL,
  34.         10, -12, 140, 12,
  35.         GADGHCOMP | GRELBOTTOM,
  36.         RELVERIFY,
  37.         BOOLGADGET,
  38.         NULL, NULL, &BackIText,
  39.         NULL, NULL,
  40.         0, NULL /* gadget ID is zero */
  41.     };
  42. struct Gadget MoreGadg = {
  43.         NULL,
  44.         300, -12, 59, 12,
  45.         GADGHCOMP | GRELBOTTOM,
  46.         RELVERIFY,
  47.         BOOLGADGET,
  48.         NULL, NULL, &MoreIText,
  49.         NULL, NULL,
  50.         MOREGADG, NULL
  51.     };
  52. struct NewWindow NWindow = {
  53.         0, 10, 640, 189,        /* left, top, width, height */
  54.         -1, -1,                 /* use screen colours */
  55.         GADGETUP                /* IDCMP flags */
  56.          | CLOSEWINDOW,
  57.         WINDOWDEPTH             /* window flags */
  58.          | WINDOWCLOSE
  59.          | WINDOWDRAG
  60.          | RMBTRAP
  61.          | ACTIVATE
  62.          | NOCAREREFRESH
  63.          | SMART_REFRESH,
  64.         &BackGadg,              /* first gadget in list */
  65.         NULL,
  66.         (UBYTE *)"The Transactor Structure Browser V 1.0",
  67.         NULL, NULL,
  68.         0, 0, 0, 0,             /* sizing limits (non-resizable) */
  69.         WBENCHSCREEN
  70.     };
  71.  
  72.  
  73. void SetupGadg()
  74. {
  75. int i;
  76.   for (i = 0; i < MAXGADG; i++) {
  77.     ChoiceText[i].BackPen     = 0;
  78.     ChoiceText[i].DrawMode    = JAM2;
  79.     ChoiceText[i].LeftEdge    = 0;
  80.     ChoiceText[i].TopEdge     = 0;
  81.     ChoiceText[i].ITextFont   = NULL;
  82.     ChoiceText[i].IText       = NULL;
  83.     ChoiceText[i].NextText    = NULL;
  84.     ChoiceGadg[i].LeftEdge    = 20;
  85.     ChoiceGadg[i].TopEdge     = i * SPACING + TOPGADG;
  86.     ChoiceGadg[i].Width       = CHOICEWIDTH;
  87.     ChoiceGadg[i].Height      = CHOICEHEIGHT;
  88.     ChoiceGadg[i].Flags       = GADGHCOMP;
  89.     ChoiceGadg[i].Activation  = RELVERIFY;
  90.     ChoiceGadg[i].GadgetType  = BOOLGADGET;
  91.     ChoiceGadg[i].GadgetText  = &ChoiceText[i];
  92.     ChoiceGadg[i].GadgetID    = i + 1;  /* gadget IDs start at 1 */
  93.   }
  94. }
  95.  
  96.  
  97. int GetChoice (num) int num;
  98. {
  99. struct IntuiMessage *GetMsg(), *message;
  100. ULONG msgclass;             /* message class from IDCMP */
  101. APTR IAddr;            /* pointer to gadget from IDCMP */
  102.   Redisplay(num);        /* put up choices in windows */
  103.   FOREVER {            /*** main event loop ***/
  104.     Wait (1L << MainWindow->UserPort->mp_SigBit);
  105.     while (message = GetMsg(MainWindow->UserPort)) {
  106.                 /* get what we need from the message port */
  107.       msgclass = message->Class;
  108.       IAddr    = message->IAddress;
  109.       ReplyMsg(message);    /* reply to message right away */
  110.                 /* check for gadget selected */
  111.       if (msgclass == GADGETUP)
  112.         return ( (int)((struct Gadget *)IAddr)->GadgetID );
  113.                 /* finish up if the close gadget is clicked */
  114.       else if (msgclass == CLOSEWINDOW)
  115.         CloseOut(); /* clean up and exit */
  116.     }
  117.   }
  118.   return(0);            /* dummy to stop warning */
  119. }
  120.  
  121.  
  122. void putHeader(string, ptr) char *string; APTR ptr;
  123. /* put title and pointer at top of screen -
  124.  * if ptr is NULL, put string only. */
  125. {
  126. char buf[80];
  127.   SetAPen(rp, 0L);
  128.   RectFill(rp, 1L, 10L, (long)MainWindow->Width-25, 27L);
  129.   SetAPen(rp, 3L);
  130.   if (ptr) {
  131.     sprintf(buf, "%d: %s (address $%lx):", level, string, ptr);
  132.     PUTTEXT(
  133.      " Member         Type                   Value (hex/decimal)",
  134.      20L, 10L + 2 * rp->TxHeight);
  135.   }
  136.   else
  137.     sprintf(buf, "%d: %s:", level, string);
  138.   PUTTEXT(buf, 20L, 10L + rp->TxHeight);
  139. }
  140.  
  141.  
  142. void OpenStuff ()
  143. {
  144.   /* open intuition & graphics libraries and window */
  145.   if (!(IntuitionBase = (struct IntuitionBase *)
  146.                  OpenLibrary("intuition.library", 0L) ) )
  147.     CloseOut();
  148.   if (!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 0L) ) )
  149.     CloseOut();
  150.   /* now attempt to open the main window */
  151.   if (!(MainWindow = OpenWindow(&NWindow)) )
  152.     CloseOut();
  153.   rp = MainWindow->RPort; /* rastport for graphics routines */
  154. }
  155.  
  156.  
  157. void CloseOut()
  158. {
  159.   /* close everything up before ending */
  160.   if (MainWindow)    CloseWindow(MainWindow);
  161.   if (IntuitionBase) CloseLibrary(IntuitionBase);
  162.   if (GfxBase)       CloseLibrary(GfxBase);
  163.   exit(0); /* exit program - we may be deeply nested */
  164. }
  165.  
  166.  
  167. void Redisplay(num) int num;
  168. /* clear window, remove old gadgets, prepare and add new ones */
  169. {
  170. struct Gadget *gadg;
  171. BOOL MoreFlag = FALSE;
  172. int i, c;
  173.   SetAPen(rp, 0L); /* rectfill with background colour to clear */
  174.   RectFill(rp, 1L, (long)TOPGADG, (long)MainWindow->Width - 2,
  175.            (long)MainWindow->Height - 2);
  176.   if (num > MAXGADG) {
  177.     num = MAXGADG;
  178.     MoreFlag = TRUE; /* put up "more" gadget */
  179.   }
  180.   /* remove all choice gadgets */
  181.   gadg = &BackGadg;
  182.   while (gadg = gadg->NextGadget)
  183.     RemoveGadget(MainWindow, gadg);
  184.   /* render gadgets according to single-digit code at
  185.    * the start of the gadget's intuitext */
  186.   for (i = 0; i < num; i++) {
  187.     ChoiceText[i].FrontPen = 1;
  188.     if ((c = *ChoiceText[i].IText) == '-' || c == '(') {
  189.       if (c == '-') {
  190.         *ChoiceText[i].IText = ' ';
  191.         ChoiceText[i].FrontPen = 2;
  192.       }
  193.       PrintIText(rp, &ChoiceText[i],
  194.                 (long)ChoiceGadg[i].LeftEdge,
  195.                 (long)ChoiceGadg[i].TopEdge);
  196.     }
  197.     else
  198.       AddGadget(MainWindow, &ChoiceGadg[i], -1L);
  199.   }
  200.   if (MoreFlag)
  201.     AddGadget(MainWindow, &MoreGadg, -1L);
  202.   /* display gadget imagery (the text) */
  203.   RefreshGadgets(&BackGadg, MainWindow, NULL);
  204. }
  205.  
  206.  
  207. void SetBackText (sflag) int sflag;
  208. {
  209.   BackIText.IText = (UBYTE *)(sflag ?
  210.              " Previous  Page " : " Previous Level ");
  211. }
  212.